﻿#ifndef CUSTOMBITMAPBUTTON_H
#define CUSTOMBITMAPBUTTON_H

#include "common.h"

class CustomBitmapButton : public wxBitmapButton
{
public:
    CustomBitmapButton(wxWindow* parent, wxWindowID id,
                      const wxBitmap& bitmap,
                      const wxString& label = wxEmptyString,
                      const wxPoint& pos = wxDefaultPosition,
                      const wxSize& size = wxDefaultSize,
                      long style = 0,
                      const wxValidator& validator = wxDefaultValidator,
                      const wxString& name = wxButtonNameStr)
        : wxBitmapButton(parent, id, bitmap, pos, size, style, validator, name)
    {
        m_label = label;
    }

    void OnPaint(wxPaintEvent& event) {
        wxPaintDC dc(this);

        // 绘制背景
        wxRect rect(GetClientRect());
        dc.SetBrush(wxBrush(GetBackgroundColour()));
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.DrawRectangle(rect);

        // 绘制位图（居中）
        if (GetBitmap().IsOk()) {
            wxSize bmpSize = GetBitmap().GetSize();
            int x = (rect.width - bmpSize.x) / 2;
            int y = (rect.height - bmpSize.y - 20) / 2; // 为文本留出空间
            dc.DrawBitmap(GetBitmap(), x, y, true);
        }

        // 绘制文本（位图下方）
        if (!m_label.empty()) {
            wxSize textSize = dc.GetTextExtent(m_label);
            int textX = (rect.width - textSize.x) / 2;
            int textY = rect.height - textSize.y - 5; // 底部留5像素边距
            dc.DrawText(m_label, textX, textY);
        }
    }

private:
    wxString m_label;
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(CustomBitmapButton, wxBitmapButton)
    EVT_PAINT(CustomBitmapButton::OnPaint)
END_EVENT_TABLE()

#endif // CUSTOMBITMAPBUTTON_H
